package io.framework.modules.noise.controller;

import io.framework.common.annotation.LogOperation;
import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.utils.ExcelUtils;
import io.framework.common.utils.Result;
import io.framework.common.validator.AssertUtils;
import io.framework.common.validator.ValidatorUtils;
import io.framework.common.validator.group.AddGroup;
import io.framework.common.validator.group.DefaultGroup;
import io.framework.common.validator.group.UpdateGroup;
import io.framework.modules.noise.dto.NoiseMonitorDTO;
import io.framework.modules.noise.excel.NoiseMonitorExcel;
import io.framework.modules.noise.service.NoiseFunctionalZoneService;
import io.framework.modules.noise.service.NoiseMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 噪音 环境质量监测
 *
 * @author Gujq email
 * @since 1.0.0 2020-06-01
 */
@RestController
@Api(tags = "噪音 环境质量监测")
public class NoiseDataController {
    @Autowired
    private NoiseMonitorService noiseMonitorService;

    @Autowired
    private NoiseFunctionalZoneService noiseFunctionalZoneService;

    @GetMapping("noise/noisemonitor/pass")
    @ApiOperation("功能区噪声达标情况")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份 例：2020", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "type", value = "1-昼间 2-夜间", paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "quarter", value = "季度： 1-第一季 2-第二季 3-第三季 4-第四季", paramType = "query", dataType = "Integer", required = true),
    })
    public Result<Map<String, Object>> pass(@ApiIgnore @RequestParam Map<String, Object> params) {

        Map<String, Object> map = new HashMap<>(4);

        List<Map<String, Object>> pass = noiseFunctionalZoneService.pass(params);
        List<Map<String, Object>> passNum = noiseFunctionalZoneService.passNum(params);
        List<Map<String, Object>> passRate = noiseFunctionalZoneService.passRate(params);
        List<Map<String, Object>> classifyInfo = noiseFunctionalZoneService.classifyInfo(params);

        map.put("pass", pass);
        map.put("passNum", passNum);
        map.put("passRate", passRate);
        map.put("classifyInfo",classifyInfo);
        return new Result<Map<String, Object>>().ok(map);
    }


    @GetMapping("noise/noisemonitor/statistics")
    @ApiOperation("道路交通噪声/区域环境噪声监测数据统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份 例：2020", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "type", value = "1-昼间 2-夜间", paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "stationId", value = "监测站点", paramType = "query", dataType = "Long", required = true),
            @ApiImplicitParam(name = "classify", value = "1-道路交通噪声 2-区域噪声", paramType = "query", dataType = "Long", required = true),
    })
    public Result<List<Map<String, Object>>> statistics(@ApiIgnore @RequestParam Map<String, Object> params) {
        List<Map<String, Object>> mapList = noiseMonitorService.statistics(params);

        return new Result<List<Map<String, Object>>>().ok(mapList);
    }

}